package com.cirkana.viewer.location.select;

import java.io.DataInputStream;
import java.io.DataOutputStream;

import com.cirkana.serial.SerializablePassData;
import com.cirkana.serial.SerializationException;

public class SelectLocationPassData extends SerializablePassData {

	private String provider;
	private Double latitude;
	private Double longitude;

	public String getProvider() {
		return provider;
	}

	public void setProvider(String provider) {
		this.provider = provider;
	}

	public Double getLatitude() {
		return latitude;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public Double getLongitude() {
		return longitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public boolean hasLocation() {
		return this.longitude != null && this.latitude != null;
	}

	public SelectLocationPassData() {
	}

	public SelectLocationPassData(String provider, Double latitude,
			Double longitude) {
		this.provider = provider;
		this.latitude = latitude;
		this.longitude = longitude;
	}

	@Override
	public void serialize(DataOutputStream out) throws SerializationException {
		serializeString(this.provider, out);
		serializeDouble(this.latitude, out);
		serializeDouble(this.longitude, out);
	}

	@Override
	public void deserialize(DataInputStream in) throws SerializationException {
		this.provider = deserializeString(in);
		this.latitude = deserializeDouble(in);
		this.longitude = deserializeDouble(in);
	}

	@Override
	public String toString() {
		StringBuilder s = new StringBuilder("{");

		s.append("provider=");
		if (this.provider == null)
			s.append("(null)");
		else
			s.append(this.provider);
		s.append(",latitude=");
		if (this.latitude == null)
			s.append("(null)");
		else
			s.append(Double.toString(this.latitude));
		s.append(",longitude=");
		if (this.longitude == null)
			s.append("(null)");
		else
			s.append(Double.toString(this.longitude));

		return s.toString();
	}

	// private Location location;
	//
	// public void setLocation(Location location) {
	// this.location = location;
	// }
	//
	// public Location getLocation() {
	// return location;
	// }
	//
	// public boolean hasLocation() {
	// return this.location != null;
	// }
	//
	// public SelectLocationPassData(Location location) {
	// this.location = location;
	// }
	//
	// @Override
	// public void serialize(DataOutputStream out) throws SerializationException
	// {
	// if (this.location == null)
	// serializeBoolean(true, out);
	// else {
	// serializeBoolean(false, out);
	// serializeString(this.location.getProvider(), out);
	// serializeDouble(this.location.getLatitude(), out);
	// serializeDouble(this.location.getLongitude(), out);
	// serializeBoolean(this.location.hasAccuracy(), out);
	// if (this.location.hasAccuracy())
	// serializeFloat(this.location.getAccuracy(), out);
	// serializeBoolean(this.location.hasAltitude(), out);
	// if (this.location.hasAltitude())
	// serializeDouble(this.location.getAltitude(), out);
	// serializeBoolean(this.location.hasBearing(), out);
	// if (this.location.hasBearing())
	// serializeFloat(this.location.getBearing(), out);
	// serializeBoolean(this.location.hasSpeed(), out);
	// if (this.location.hasSpeed())
	// serializeFloat(this.location.getSpeed(), out);
	// serializeLong(this.location.getTime(), out);
	// }
	// }
	//
	// @Override
	// public void deserialize(DataInputStream in) throws SerializationException
	// {
	// this.location = null;
	// if (!deserializeBoolean(in)) {
	// this.location = new Location(deserializeString(in));
	// this.location.setLatitude(deserializeDouble(in));
	// this.location.setLongitude(deserializeDouble(in));
	// if (deserializeBoolean(in))
	// this.location.setAccuracy(deserializeFloat(in));
	// if (deserializeBoolean(in))
	// this.location.setAltitude(deserializeDouble(in));
	// if (deserializeBoolean(in))
	// this.location.setBearing(deserializeFloat(in));
	// if (deserializeBoolean(in))
	// this.location.setSpeed(deserializeFloat(in));
	// this.location.setTime(deserializeLong(in));
	// }
	// }
	//
	// @Override
	// public String toString() {
	// StringBuilder s = new StringBuilder("{");
	//
	// s.append("location=");
	// if (this.location == null)
	// s.append("(null)");
	// else {
	// s.append("{provider=");
	// if (this.location.getProvider() == null)
	// s.append("(null)");
	// else
	// s.append(this.location.getProvider());
	// s.append(",latitude=");
	// s.append(Double.toString(this.location.getLatitude()));
	// s.append(",longitude=");
	// s.append(Double.toString(this.location.getLongitude()));
	// s.append(",accuracy=");
	// if (this.location.hasAccuracy())
	// s.append(Float.toString(this.location.getAccuracy()));
	// else
	// s.append("(null)");
	// s.append(",altitude=");
	// if (this.location.hasAltitude())
	// s.append(Double.toString(this.location.getAltitude()));
	// else
	// s.append("(null)");
	// s.append(",bearing=");
	// if (this.location.hasBearing())
	// s.append(Float.toString(this.location.getBearing()));
	// else
	// s.append("(null)");
	// s.append(",speed=");
	// if (this.location.hasSpeed())
	// s.append(Float.toString(this.location.getSpeed()));
	// else
	// s.append("(null)");
	// s.append(",time=");
	// s.append(Long.toString(this.location.getTime()));
	// s.append("}");
	// }
	// s.append("}");
	//
	// return s.toString();
	// }
}
